home *** CD-ROM | disk | FTP | other *** search
/ Compendium Deluxe 1 / LSD Compendium Deluxe 1.iso / a / programming / misc / ada1110b.lha / AmigaSources / hdr.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-10  |  65.2 KB  |  2,206 lines

  1. /*
  2.  * Copyright (C) 1985-1992  New York University
  3.  * 
  4.  * This file is part of the Ada/Ed-C system.  See the Ada/Ed README file for
  5.  * warranty (none) and distribution info and also the GNU General Public
  6.  * License for more details.
  7.  
  8.  */
  9. #ifndef _hdr_h
  10. #define _hdr_h
  11.  
  12. /*
  13.     Symbol Table Definitions for Ada/ED in C 
  14.  
  15. Change history:
  16.  
  17. October 1989    gs
  18. Remove Sybmol Table stuff and put in separate file symbol.h.
  19. This is included from this file now.
  20.  
  21. July 1989    gs
  22. Add field to node N_OPERAND to hold either the register or literal value
  23. associated with the Amiable generated code for the Node. 
  24.  
  25. 19-dec-86    gs
  26. Revise format for nodes storing left span (only) for terminal nodes,
  27. and overlaying these 2 fields with N_AST1 of nonterminal nodes.
  28.  
  29. 18-sep-86    ds
  30. Revise format for nodes used for aggregates to permit overlaying of n_unq
  31. and n_ast3 fields. This requires that n_ast3 not be used for such nodes, so
  32. a new node kind  - as_aggregate_list - has been introduced and placed in the
  33. n_ast1 position to hold the two nodes formerly
  34. kept in n_ast1 and n_ast2. The former n_ast3 field is now at n_ast2.
  35. The affected node kinds are as_array_aggregate, as_record_aggregate,
  36. as_array_ivalue and as_record_ivalue.
  37.  
  38. 15-nov-85    gs
  39. add CONSTRAINT_ACCESS for subtypes of access types.
  40.  
  41. 28-sep-85    ds
  42. defintions of ATTR_ codes moved to separate inclusion file attr.h
  43.  
  44. 14-aug-85    ds
  45. Add new symbol table field type_kind, used only by code_generator.
  46.  
  47. 8-jul-85    ds
  48. Add new member const_fixed to Const structure used for fixed-point 
  49. values during code generation.
  50.  
  51. 24-apr-85    ds
  52. Support only lower case na_ codes, drop NA_ codes. Only NA_ENUM
  53. was actually used in upper case and this has been changed to lower case
  54. where so used. Also, delete declarations for externs that return int's.
  55.  
  56. 16-apr-65    ds
  57. Reduce the size of the FORDECLARED macro by using (new) procedures
  58. fordeclared_1() and fordeclared_2() to initiate and advance the
  59. iteration, respectively.
  60.  
  61. 3-apr-85
  62. add structure definitions for Symbolmap and Nodemap because node_map
  63. must be global (to all of chapter 12).
  64.  
  65. 21-mar-85
  66. Redefine associated_name to associated_symbols, a tuple of symbols.
  67. This is described in more detail in ghdr.c.
  68.  
  69. 13-mar-85
  70. The macro index_type was conditionally defined only for SEM since
  71. this name was used as variable name within code generator. Such usages
  72. within code generator have been changed to use name indx_type so that
  73. conditional definition no longer needed. This avoids need for SEM
  74. conditional option in this case.
  75.  
  76. 12-mar-85
  77. Redo declarations for nodes and symbols so that single struct used for
  78. both SEM and GEN with all fields defined. Fields used only by GEN are
  79. defined at end of symbol_s declaration so that (eventually) SEM can ignore
  80. these fields when building entries. For now will process full entry.
  81. I merged in corrections from sem hdr.c through version 1.46.
  82.  
  83. 4-mar-85
  84. Add codes CODE_SLOTS etc for string used as third arg to 
  85. select entry (this is enumeration type).
  86. Add symbol table field associated_name. THis is used for example
  87. to give the _type variable associated with an array name, etc.
  88. In SETL version, these names are referenced by taking name and appending
  89. string...
  90.  
  91. 21-jan-85
  92. modify to permit use with GEN and SEM phases. Use conditional symbols
  93. GEN and SEM to indicate code needed only for that phase. 
  94.  
  95. 31-dec-84
  96. add NEEDNAME field to indicate symbols for which identifier needed as
  97. name for SETL code generator. Add CONSTRAINT_ARRAY code for use when
  98. writing out signatures for constrained arrays.
  99.  
  100. 26-dec-84    ds
  101. add N_COUNT field to hold NODE_COUNT values for node.
  102.  
  103. 16-dec-84    ds
  104. Use overloads for literal map for enumeration types, accessed using
  105. macro literal_map. This was modified to used declared field due to original
  106. handling of misc_type_attributes. Now that type_attr field available, it is
  107. possible (and necessary to avoid bugs) to use overloads, as this avoids
  108. adding further code for special handling of declared map.
  109.  
  110. 12-nov-84    ds
  111. make is_anonymous_task a procedure.
  112.  
  113. 08-nov-84    ds
  114. add n_spans field to Node_s for spans information.
  115. NOTE: attempt to declare n_spans as short (which it should be) caused
  116. very mysterious failures in malloc for no apparent reason; hence n_spans
  117. is declared as int.
  118. add s_type_attr field to Symbol_s to hold 'miscellaneous_type_attributes'
  119. which cannot be kept in overloads field in C version. Change definition
  120. of misc_type_attributes macro so it now refers to new field and definition
  121. of private_dependents macro so it now refers to overloads.
  122.  
  123. 31-oct-84    ds
  124. Node that numeric_constraint for 'delta' now has four nodes; new
  125. one is 'small' with new macro numeric_constraint_small.
  126.  
  127. 15-oct-84    ds
  128. Merge const.h and pdecl.h files into this file.
  129.  
  130. 6-oct-84    ds
  131. Revise to use seq_node tuple to record allocated nodes. Assigned values of
  132. N_SEQ start with 1, seq_node[i] is address of node with N_SEQ == i.
  133. seq_node_n is number of actual nodes so far allocated; only the first
  134. seq_node_n entries of seq_node correspond to allocated nodes, the remaining
  135. entries provide expansion space.
  136. Similarly for allocated symbols, using seq_symbol.
  137. SEQ_NODE_INC defines number of new entries allocated when have to expand
  138. seq_node, similarly for SEQ_SYMBOL_INC and seq_symbol.
  139. */
  140. #define SEQ_NODE_INC 50
  141. #define SEQ_SYMBOL_INC    50
  142.  
  143. /*
  144. ds 5-oct-84
  145. Delete n_anon field for node, add n_seq field for node sequence number.
  146. Also add n_unit field for unit number of node.
  147. Change name of Symbol field sequence to s_seq and add s_unit field
  148. for a Symbol to hold unit number.
  149. ds 29-sep-84
  150. I originally made numeric_constraint data structure (see na_subtype)
  151. because I thought lo, hi, etc were actual values. It turns out they
  152. are just nodes, and it is more convenient to represent contraints
  153. as tuples, as is done in SETL. I have modified code to do this,
  154. thbough macors numeric_constraint_low, etc, are still used. They
  155. can be edited out later. But structure numeric_constraint_s is now
  156. gone.
  157.  
  158. ds 1 aug
  159. Modify symbol sequence handling as follows:
  160. unit_symbol is tuple of symbol table pointers for current unit - the
  161. i-th entry should have sequence number i. unit_symbols is number of
  162. symbols allocated. To avoid reallocating the tuple unit_symbol when
  163. each new symbol is allocated, unit_symbol_length will be allocated
  164. length, and must always be >= unit_symbols.
  165. Will also have unit_scope, a tuple with an entry for each new scope
  166. created within a compilation unit.
  167.  
  168.  
  169. ds 20 july
  170. Need to check macro definitions to see where need parentheses
  171. around argument names.
  172.  
  173. ds 12 july
  174. add new symbol table field 'sequence' that contains sequence number
  175. assigned for symbols. The global SEQUENCE_NUMBER gives the number of
  176. the last symbol allocated; numbering starts with one. The global
  177. SEQUENCE_LIST is a tuple indexed by sequence numbers that gives the
  178. address of the corresponding symbol table entry.
  179.  
  180. ----
  181.  
  182. This file contains the (proposed) definitions and declarations for symbol
  183. table access for Ada/Ed-C, the C version of Ada/Ed.
  184.  
  185.  
  186. Coding conventions:
  187. -------------------
  188.  
  189. In this section we outline a suggested set of coding conventions that
  190. are used in the remainder of this document.
  191.  
  192. C does not have the 'end-of-line' comment using a single character,
  193. but requires that all comments begin with slash asterisk and end
  194. with asterisk slash (we are naming the characters here to avoid
  195. having a comment within a comment!).
  196. There are a variety of conventions used for writing comments in C,
  197. including the all too common convention of writing no comments at all
  198. (a practice we do not intend to follow). 
  199.  
  200. We follow the following convention:
  201.  
  202. If a line begins with white space followed by the comment opener, then
  203. it is the first of possibly several comment lines. The comment continues
  204. up to and including the next line containing the comment closer. No code
  205. may follow the comment closer on the last line. 
  206.  
  207. If a line otherwise contains a comment opener, then it must also contain
  208. the comment closer, and no code must follow the comment closer.
  209.  
  210. This permits each line to be classified as either code followed by a
  211. comment extending to the end of the line, code with no comment, or part
  212. of a comment, and makes it possible to write a filter to convert to
  213. other comment conventions. 
  214.  
  215.  
  216. Significance of Character Case
  217. ------------------------------
  218.  
  219. In C, unlike SETL, the case of an identifier is significant, so that
  220. 'I' and 'i' are distinct identifiers.  The SETL version uses such
  221. case-ignorant names at times; and these will have to be removed as
  222. part of the translation to C. In general, we will follow the following
  223. rules, with occasional exceptions, noted in comments below, which will
  224. simplify the translation of the SETL source to C; such exceptions
  225. will typically introduce mixed-case identifiers.
  226.  
  227. 1. Names defined by #define are capitalized, i.e., defined constants
  228. and macros.
  229.  
  230. 2. SETL strings used as discriminants will usually be changed to 
  231. defined constants, with some appropriate prefix, and will thus be capitalized.
  232.  
  233. 3. User-defined type names have their first letter capitalized.
  234.  
  235. 4. Structure tags are to be defined with initial letter capitalized
  236. and are given the same name via a typdef. For example, 
  237.  
  238.   struct Str { ... } Str;
  239.  
  240. 5. Since much of the code will involve merely passing pointers to
  241. structures, we will often use type names that in fact just pointers.
  242. This requires two names, one for the structure and one for a pointer
  243. to the structure. Having two names permits us to write
  244.     Str    x,y,z;
  245. instead of
  246.     Str    *x,*y,*z;
  247. For such cases, our convention is to use
  248.     Name
  249. for a pointer to the structure, and
  250.     Name_s
  251. for the structure itself. This permits us to write code using the first
  252. approach, avoiding needless (since they are always implicit) asterisks
  253. in declarations and other references, such as casts, involving the type
  254. name. 
  255.  
  256. */
  257.  
  258. /* Include declarations for sets and tuples */
  259.  
  260. #include <stdlib.h>
  261. #include <stdio.h>
  262. #include <ctype.h>
  263. #include <string.h>
  264. #include "config.h"
  265. #include "arith.h"
  266. /*
  267.         SYMBOL TABLE
  268.  
  269.  
  270.    In SETL, the symbol table is represented as several maps:
  271. nature, type_of, scope_of, signature, overloads and alias.
  272. In C, a symbol table entry will be a structure, with fields 
  273. corresponding to the SETL maps, in the order given above.
  274. Not all fields are defined for each entry. We provide a single 
  275. declaration and leave it up to the allocator (which will be given the
  276. nature) to allocate the proper length entry.
  277.  
  278. The alias field is used for derived subprograms and renamed subprograms,
  279. and also for types.
  280.  
  281. The overloads field is defined for procedures, functions, literals and
  282. operators; for packages it is used to store private declarations.
  283.  
  284. The SETL version has declared as a map; in the C version this will be
  285. a field in symbol table entries for which it is defined.
  286.  
  287. The orig_name field gives the original name of the symbol.
  288. */
  289.  
  290.  
  291. typedef struct Declaredmap_s *Declaredmap;
  292.  
  293. #ifdef AMIABLE
  294. /*
  295. #include "gena.h"
  296. */
  297.             /* it includes symbol.h */
  298. #else
  299. #include "symbol.h"
  300. #endif
  301.  
  302. /* 
  303. Each entry in the symbol type has a nature. The nature is represented
  304. as a string in the SETL source, and as one of the following constant
  305. values of the form na_ in C. 
  306. */
  307.  
  308. /*        AST declarations and definitions
  309.  
  310. This file contains the declarations and definitions for the
  311. AST representation for the ADA/ED-C ADASEM phase.
  312.  
  313. The following summary is taken from file [ada.dev]ast.doc
  314. (perhaps should merge in this whole file later):
  315.  
  316.     The following is a description of the nodes used in building the
  317. abstract syntax tree (AST) for an ADA source program (in the SETL
  318. version).
  319.  
  320.     The AST is represented as a collection of nodes on which certain
  321. maps are defined to form the tree. The nodes correspond to 
  322. non-terminals such as "pragma", "object_declaration", etc...  Nodes
  323. are represented by setl integers and are described as either equivalent
  324. to other nodes or by specifying values for the maps N_KIND, N_AST,
  325. N_VAL, and/or N_LIST that are defined on them.    These maps are used as
  326. follows:
  327.  
  328. N_KIND(node) is a string (for now) that names the node and serves as a
  329. discriminant for the other maps defined on it.
  330.  
  331. N_AST(node) is a tuple of nodes, corresponding to the right-hand side
  332. of a production for the node.
  333.  
  334. N_VAL(node) is defined for terminal nodes. For simple_names it is the
  335. source identifier for that node. The semantic actions use the N_VAL map
  336. to store miscellaneous information used by the EMIT routine.
  337.  
  338. N_LIST(node) is a tuple of arbitrary length whose components are nodes
  339. of the same kind. N_LIST(node) is defined for all occurrences in the
  340. grammar of arbitrary repetitions. These are noted below as nodes of the
  341. form <node...>, and have the N_KIND 'list'.
  342.  
  343.  
  344.  
  345. SEMANTIC PROCESSING.
  346.  
  347.  
  348. The semantic routines are driven by the N_KIND of each AST node. In most
  349. cases the AST is not directly modified by the semantic actions; rather,
  350. several maps, including the symbol table, are constructed and updated. 
  351. The following maps are used by sem:
  352.  
  353. N_UNQ(node) is the unique name corresponding to a name node. The N_KIND
  354. of such a node is always set to 'simple_name'. The N_UNQ is a symbol
  355. table pointer, through which all attributes of an entity are retrieved.
  356.  
  357. N_NAMES(node) is the overloaded set of names coresponding to a name node
  358. before overload resolution is performed. It is used only during type
  359. resolution.
  360.  
  361. The above two maps, N_UNQ and N_NAMES, are defined only on name nodes.
  362.  
  363. N_TYPE(node) is the unique name of the type of an expression node. This
  364. field is set for all expressions and names that are not simple names.
  365.  
  366. N_PTYPES(node) is the set of possible types of an overloaded construct,
  367. before resolution. It is also useless after type resolution.
  368.  
  369. The maps N_TYPE and N_PTYPES are defined only on expression nodes.
  370.  
  371. -- end excerpt from AST.DOC
  372.  
  373. In C N_KIND will be represented as an integer constant of the form AS_.
  374.  
  375. A node has N_UNQ and N_NAMES defined; or it has     N_TYPE and
  376. N_PTYPES defined. Field n_sym is used for N_UNQ or N_TYPE, which
  377. are both pointers to symbol table entries. Field n_set is used for
  378. N_NAMES or N_PTYPES, which are both pointers to sets of symbol table
  379. pointers.
  380.  
  381. The fields for N_LIST and N_VAL can overlap, and are hence declared
  382. as a union.
  383.  
  384. The fields for N_AST and N_LIST can overlap since they are never both
  385. defined for a node
  386.  
  387. Note that for the case where the SETL AST map id defined, the number of
  388. components is fixed for a particular kind, and at most five. We thus
  389. define fields n_ast1, n_ast2 ... n_ast5 and allocate only as many fields
  390. as needed for each particular node. It is not necessary to keep the 
  391. number of AST entries, since the length can be deduced from N_KIND. 
  392.  
  393. */
  394.  
  395. typedef struct Span_s *Span;   /* pointer to spans information */
  396.  
  397. typedef struct Span_s {
  398.     short line;
  399.     short col;
  400. } Span_s;
  401.  
  402. typedef struct Node_s *Node; /* Node is pointer to Node_s */
  403. #define NODE_SIZE  sizeof(Node_s)
  404.  
  405. typedef struct Node_s
  406. {
  407. #ifndef IBM_PC
  408.     struct {
  409.     unsigned n_kind:8;
  410.     unsigned n_unit:8;
  411.     unsigned n_side:1;
  412.     unsigned n_overloaded:1;
  413.     } n_flags;
  414.     
  415.     short n_seq;
  416. #else
  417.     struct {
  418.     unsigned n_kind:8;
  419.     unsigned n_unit:8;
  420.     } n_flag1;
  421.  
  422.     struct {
  423.     unsigned n_side:1;
  424.     unsigned n_seq:14;
  425.     unsigned n_overloaded:1;
  426.     } n_flag2;
  427.  
  428. #endif
  429.  
  430.     union {
  431.     Node    n_ast1;
  432.     Span_s    n_span;
  433.     } nu1;
  434.  
  435.      union {
  436.     Node    n_ast2;
  437.     Tuple    n_list;
  438.     char    *n_val; 
  439.     } nu2;
  440.      union { 
  441.     Node    n_ast3;
  442.     Set    n_names;
  443.     Symbol    n_unq; 
  444.     } nu3;
  445.      union {
  446.     Node    n_ast4;
  447.     Set    n_ptypes;
  448.     Symbol    n_type; 
  449.     } nu4;
  450. #ifdef AMIABLE
  451.     Operand_s n_operand;
  452. #endif
  453. }  Node_s;
  454.  
  455. struct unit {
  456.     char *name;
  457.     int isMain;
  458.     char *libUnit;
  459.     struct {
  460.         char *fname;
  461.         char *obsolete;
  462.         char *currCodeSeg;
  463.         char *localRefMap;
  464.         char *compDate;
  465.     } libInfo;
  466.     struct {
  467.         char *preComp;
  468.         char *pragmaElab;
  469.         char *compDate;
  470.         char *symbols;
  471.         int  numberSymbols;
  472.         char *unitDecl;
  473.     } aisInfo;
  474.     struct {
  475.         char *tableAllocated;
  476.         int nodeCount;
  477.         int rootSeq;
  478.     } treInfo;
  479. };
  480.  
  481. #define MAX_UNITS 100
  482.  
  483. #ifdef IBM_PC
  484. #define N_KIND(p)    ((p)->n_flag1.n_kind)
  485. #define N_UNIT(p)    ((p)->n_flag1.n_unit)
  486. #define N_OVERLOADED(p)    ((p)->n_flag2.n_overloaded)
  487. #define N_SIDE(p)    ((p)->n_flag2.n_side)
  488. #define N_SEQ(p)    ((p)->n_flag2.n_seq)
  489. #else
  490. #define N_KIND(p)    ((p)->n_flags.n_kind)
  491. #define N_UNIT(p)    ((p)->n_flags.n_unit)
  492. #define N_OVERLOADED(p)    ((p)->n_flags.n_overloaded)
  493. #define N_SIDE(p)    ((p)->n_flags.n_side)
  494. #define N_SEQ(p)    ((p)->n_seq)
  495. #endif
  496. #define N_SPAN0(p)    ((p)->nu1.n_span.line)
  497. #define N_SPAN1(p)    ((p)->nu1.n_span.col)
  498. #define N_AST1(p)    ((p)->nu1.n_ast1)
  499. #define N_VAL(p)    ((p)->nu2.n_val)
  500. #define N_LIST(p)    ((p)->nu2.n_list)
  501. #define N_AST2(p)    ((p)->nu2.n_ast2)
  502. #define N_AST3(p)    ((p)->nu3.n_ast3)
  503. #define N_UNQ(p)    ((p)->nu3.n_unq)
  504. #define N_NAMES(p)    ((p)->nu3.n_names)
  505. #define N_AST4(p)    ((p)->nu4.n_ast4)
  506. #define N_TYPE(p)    ((p)->nu4.n_type)
  507. #define N_PTYPES(p)    ((p)->nu4.n_ptypes)
  508. #ifdef AMIABLE
  509. #define N_OPERAND(p)    ((p)->n_operand)
  510. #endif
  511.  
  512. /* N_D_ macros define which fields defined for node according to kind */
  513. #define N_D_AST1 1
  514. #define N_D_AST2 2
  515. #define N_D_AST3 4
  516. #define N_D_AST4 8
  517. #define N_D_LIST 16
  518. #define N_D_VAL 32
  519. #define N_D_UNQ 64
  520. /* was N_CHAOS 128  ds 10-29-86 */
  521. #define N_D_TYPE 256
  522.  
  523. #define N_AST1_DEFINED(p) (N_DEFINED[p]&N_D_AST1)
  524. #define N_AST2_DEFINED(p) (N_DEFINED[p]&N_D_AST2)
  525. #define N_AST3_DEFINED(p) (N_DEFINED[p]&N_D_AST3)
  526. #define N_AST4_DEFINED(p) (N_DEFINED[p]&N_D_AST4)
  527. #define N_VAL_DEFINED(p) (N_DEFINED[p]&N_D_VAL)
  528. /* N_UNQ_DEFINED and N_TYPE defined are set for nodes for which these fields
  529.  * are to written to library files and for which the fields are to be set 
  530.  * during instantiation.
  531.  */
  532. #define N_UNQ_DEFINED(p) (N_DEFINED[p]&N_D_UNQ)
  533. #define N_TYPE_DEFINED(p) (N_DEFINED[p]&N_D_TYPE)
  534. #define N_LIST_DEFINED(p) (N_DEFINED[p]&N_D_LIST)
  535.  
  536. /*
  537. From schonber Tue Feb 11 00:51:07 1986
  538. Date: Tue, 11 Feb 86 00:51:03 est
  539. From: schonber
  540. Received: by nyu-acf2.arpa; Tue, 11 Feb 86 00:51:03 est
  541. To: shields
  542. Subject: data compression.
  543. Status: R
  544.  
  545. Have you tried overlapping N_PTYPES and N_TYPE? This should be safe in all
  546. cases, as they have always disjoint usage. A further possibility is N_NAMES
  547. and N_UNQ, but this requires the use of some additional bit to indicate whether
  548. an entity is overloaded or not. By the way, N_NAMES is ONLY defined on simple
  549. names and ops, so maybe overlapped with unused N_AST field. THere is still some
  550. juice to be squeezed out.
  551.  
  552. Franck says:
  553.     N_NAMES and N_UNQ cannot be overlaid
  554.  
  555. From chiabaut@nyu.arpa Thu Sep 11 10:27:20 1986
  556. Received: from nyu.arpa by nyu-acf2.arpa; Thu, 11 Sep 86 10:27:17 edt
  557. Date: Thu, 11 Sep 86 10:28:48 edt
  558. From: chiabaut@nyu.arpa (Jerome Chiabaut)
  559. Message-Id: <8609111428.AA03384@nyu.arpa>
  560. Received: by nyu.arpa; Thu, 11 Sep 86 10:28:48 edt
  561. To: shields@nyu-acf2.arpa
  562. Subject: Re: overlaying n_unq and n_type
  563. Status: RO
  564.  
  565.   I'm not sure but i think that an aggregate or array-aggregate has more than
  566. two n_asts defined along with n_type and n_unq. In any case the idea is that
  567. for a few nodes it might require to change the shape of the tree.
  568.      Jerome
  569.  
  570. */
  571.  
  572.  
  573. #define as_pragma  0
  574. #define as_arg    1
  575. #define as_obj_decl  2
  576. #define as_const_decl  3
  577. #define as_num_decl  4
  578. #define as_type_decl  5
  579. #define as_subtype_decl     6
  580. #define as_subtype_indic  7
  581. #define as_derived_type     8
  582. #define as_range  9
  583. #define as_range_attribute  10
  584. #define as_constraint  11
  585. #define as_enum     12
  586. #define as_int_type  13
  587. #define as_float_type  14
  588. #define as_fixed_type  15
  589. #define as_digits  16
  590. #define as_delta  17
  591. #define as_array_type  18
  592. #define as_box    19
  593. #define as_subtype  20
  594. #define as_record  21
  595. #define as_component_list  22
  596. #define as_field  23
  597. #define as_discr_spec  24
  598. #define as_variant_decl     25
  599. #define as_variant_choices  26
  600. #define as_string  27
  601. #define as_simple_choice  28
  602. #define as_range_choice     29
  603. #define as_choice_unresolved  30
  604. #define as_others_choice  31
  605. #define as_access_type    32
  606. #define as_incomplete_decl  33
  607. #define as_declarations     34
  608. #define as_labels  35
  609. #define as_character_literal  36
  610. #define as_simple_name    37
  611. #define as_call_unresolved  38
  612. #define as_selector  39
  613. #define as_all    40
  614. #define as_attribute  41
  615. #define as_aggregate  42
  616. #define as_parenthesis    43
  617. #define as_choice_list    44
  618. #define as_op  45
  619. #define as_in  46
  620. #define as_notin  47
  621. #define as_un_op  48
  622. #define as_int_literal    49
  623. #define as_real_literal     50
  624. #define as_string_literal  51
  625. #define as_null     52
  626. #define as_name     53
  627. #define as_qualify  54
  628. #define as_new_init  55
  629. #define as_new    56
  630. #define as_statements  57
  631. #define as_statement  58
  632. #define as_null_s  59
  633. #define as_assignment  60
  634. #define as_if  61
  635. #define as_cond_statements  62
  636. #define as_condition  63
  637. #define as_case     64
  638. #define as_case_statements  65
  639. #define as_loop     66
  640. #define as_while  67
  641. #define as_for    68
  642. #define as_forrev  69
  643. #define as_block  70
  644. #define as_exit     71
  645. #define as_return  72
  646. #define as_goto     73
  647. #define as_subprogram_decl  74
  648. #define as_procedure  75
  649. #define as_function  76
  650. #define as_operator  77
  651. #define as_formal  78
  652. #define as_mode     79
  653. #define as_subprogram  80
  654. #define as_call     81
  655. #define as_package_spec     82
  656. #define as_package_body     83
  657. #define as_private_decl     84
  658. #define as_use    85
  659. #define as_rename_obj  86
  660. #define as_rename_ex  87
  661. #define as_rename_pack    88
  662. #define as_rename_sub  89
  663. #define as_task_spec  90
  664. #define as_task_type_spec  91
  665. #define as_task     92
  666. #define as_entry  93
  667. #define as_entry_family     94
  668. #define as_accept  95
  669. #define as_delay  96
  670. #define as_selective_wait  97
  671. #define as_guard  98
  672. #define as_accept_alt  99
  673. #define as_delay_alt  100
  674. #define as_terminate_alt  101
  675. #define as_conditional_entry_call  102
  676. #define as_timed_entry_call  103
  677. #define as_abort  104
  678. #define as_unit     105
  679. #define as_with_use_list  106
  680. #define as_with     107
  681. #define as_subprogram_stub  108
  682. #define as_package_stub     109
  683. #define as_task_stub  110
  684. #define as_separate  111
  685. #define as_exception  112
  686. #define as_except_decl    113
  687. #define as_handler  114
  688. #define as_others  115
  689. #define as_raise  116
  690. #define as_generic_function  117
  691. #define as_generic_procedure  118
  692. #define as_generic_package  119
  693. #define as_generic_formals  120
  694. #define as_generic_obj    121
  695. #define as_generic_type     122
  696. #define as_gen_priv_type  123
  697. #define as_generic_subp     124
  698. #define as_generic  125
  699. #define as_package_instance  126
  700. #define as_function_instance  127
  701. #define as_procedure_instance  128
  702. #define as_instance  129
  703. #define as_length_clause  130
  704. #define as_enum_rep_clause  131
  705. #define as_rec_rep_clause  132
  706. #define as_compon_clause  133
  707. #define as_address_clause  134
  708. #define as_any_op  135
  709. #define as_opt    136
  710. #define as_list     137
  711. #define as_range_expression  138
  712. #define as_arg_assoc_list  139
  713. #define as_private  140
  714. #define as_limited_private  141
  715. #define as_code     142
  716. #define as_line_no  143
  717. #define as_index  144
  718. #define as_slice  145
  719. #define as_number  146
  720. #define as_convert  147
  721. #define as_entry_name  148
  722. #define as_array_aggregate  149
  723. #define as_record_aggregate  150
  724. #define as_ecall  151
  725. #define as_call_or_index  152
  726. #define as_ivalue  153
  727. #define as_qual_range  154
  728. #define as_qual_index  155
  729. #define as_qual_discr  156
  730. #define as_qual_arange    157
  731. #define as_qual_alength     158
  732. #define as_qual_adiscr    159
  733. #define as_qual_aindex    160
  734. #define as_check_bounds     161
  735. #define as_discr_ref  162
  736. #define as_row    163
  737. #define as_current_task     164
  738. /* new node added aug 84 by banner */
  739. #define as_check_discr    165
  740. #define as_end    166
  741. #define as_terminate 167
  742. #define as_exception_accept 168
  743. #define as_test_exception 169
  744. #define as_create_task 170
  745. #define as_predef    171
  746. #define as_deleted 172
  747. #define as_insert 173
  748. #define as_arg_convert 174
  749. #define as_end_activation 175
  750. #define as_activate_spec 176
  751. #define as_delayed_type 177
  752. #define as_qual_sub 178
  753. #define as_static_comp 179
  754. #define as_array_ivalue 180
  755. #define as_record_ivalue 181
  756. #define as_expanded 182
  757. #define as_choices 183
  758. #define as_init_call 184
  759. #define as_type_and_value 185
  760. #define as_discard 186
  761. /* as_unread used by C version to indicate node not yet read in.
  762.  * The SETL test N_KIND(node)=om thus becomes
  763.  * N_KIND(node)==as_unread in C
  764.  */
  765. #define as_unread 187
  766. #define as_string_ivalue 188
  767. #define as_instance_tuple 189
  768. #define as_entry_family_name 190
  769. /* The next two kinds are used internally only by astread */
  770. #define as_astend    191
  771. #define as_astnull    192
  772. /* aggregate_list added 9-15-86 so can overlay n_ast3 and n_unq  (DS) */
  773. #define as_aggregate_list 193
  774. #define as_interfaced 194
  775. #define as_record_choice 195
  776. #define as_subprogram_decl_tr 196
  777. #define as_subprogram_tr 197
  778. #define as_subprogram_stub_tr 198
  779. #define as_rename_sub_tr 199
  780.  
  781. /*
  782. PARSE TREE
  783. ----------
  784. This section describes changes and additions to the parse tree (nodes) 
  785. in the C version:
  786.  
  787. AS_ATTRIBUTE
  788. ------------
  789. In the SETL version a node of this kind has as its first subnode (AST1)
  790. a name-type node with a string giving the attribute name. The SETL version
  791. alters this string by adding a prefix of "T_" or "O_" to indicate attributes
  792. for types and objects, respectively. In C this is done by storing a numeric
  793. attribute code in the N_VAL field for the as_attribute node. The attribute
  794. codes are chosen so that where "T_" and "O_" codes are needed, the
  795. codes are in the order    base code, then "O_" code and then "T_" code.
  796. The procedure attribute_str() maps numeric codes to their string
  797. equivalents. The original subnode is left intact; all manipulation of
  798. codes is done with the numeric codes.
  799. The codes are defined in header file attr.h:
  800. */
  801.  
  802.  
  803. /*
  804.  
  805. SYMBOL TABLE 
  806. ------------
  807. Let us now continue out the description of the symbol table entries.
  808. Entries whose nature ends in '_SPEC' have the same form as the
  809. corresponding nature with '_SPEC' removed. The initial entry
  810. with '_SPEC' is made when the specification is seen; the other
  811. is made when the body is encountered.
  812.  
  813. For a field, 'not used' means the field is defined but not used, so that
  814. its contents are not relevant (they will, and should, be NULL, the null
  815. pointer); 
  816. */
  817.  
  818. /* 
  819.  * Define nature codes. To assist conversion of SETL source each
  820.  * code is defined in both upper and lower case. 
  821.  */
  822.  
  823. #define na_op  1
  824. #define na_un_op  2
  825. #define na_attribute  3
  826. #define na_obj    4
  827. #define na_constant  5
  828. #define na_type     6
  829. #define na_subtype  7
  830. #define na_array  8
  831. #define na_record  9
  832. #define na_enum     10
  833. #define na_literal  11
  834. #define na_access  12
  835. #define na_aggregate  13
  836. #define na_block  14
  837. #define na_procedure_spec  15
  838. #define na_function_spec  16
  839. #define na_procedure  17
  840. #define na_function  18
  841. #define na_in  19
  842. #define na_inout  20
  843. #define na_out    21
  844. #define na_package_spec     22
  845. #define na_package  23
  846. #define na_task_type  24
  847. #define na_task_type_spec  25
  848. #define na_task_obj  26
  849. #define na_task_obj_spec  27
  850. #define na_entry  28
  851. #define na_entry_family     29
  852. #define na_entry_former     30
  853. #define na_generic_procedure_spec  31
  854. #define na_generic_function_spec  32
  855. #define na_generic_package_spec     33
  856. #define na_generic_procedure  34
  857. #define na_generic_function  35
  858. #define na_generic_package  36
  859. #define na_exception  37
  860. #define na_private_part     38
  861. #define na_void     39
  862. #define na_null     40
  863. #define na_discriminant     41
  864. #define na_field  42
  865. #define na_label  43
  866. #define na_generic_part     44
  867. /* na_subprog, na_body and na_task referenced in sem0.c, addedm15-may 
  868.  for debugging 
  869.  */
  870. #define na_subprog 45
  871. #define na_body 46
  872. #define na_task 47
  873. /* added for use with symbol_op (cf find_qual (8) and result_types(4))*/
  874. #define na_task_body 48
  875.  
  876. /*
  877. NA_ACCESS:
  878. ----------
  879. denotes an access type.
  880.  
  881. type_of: map of an access type is itself. The macro
  882. designated_type(access_type) retrieves the unique name of
  883. the type of designated objects of the access type.
  884. this macro is also available on     subtypes of access types.
  885.  
  886. signature: designated_type (as noted above)
  887.  
  888. overloads: not used
  889.  
  890. type_attr:  misc_type_attributes
  891.  
  892. NA_AGGREGATE:    
  893. -------------
  894. Every array and record declaration introduces an aggre-
  895. gate into the environment, i.e. one possible meaning
  896. for any aggregate expression appearing in the code. In order
  897. to disambiguate such an expression, it is convenient to view
  898. aggregates as overloaded constructs. Each aggregate entry
  899. is uniquely characterized by its type (held in type_of).
  900. Note that constraining an array does not introduce a new
  901. aggregate. Properly speaking, it is only a new sequence type
  902. (an unbounded array) which introduces a new aggregate.
  903.  
  904. type_of: (unique characterization of) type
  905.  
  906. signature: not used
  907.  
  908. overloads: set of other aggregate types (symbols) in same scope
  909.  
  910.  
  911. NA_ARRAY:
  912. ---------
  913. This denotes an entry for an array type. This entry is built
  914. when an array declaration is processed, and also when a task
  915. family or an entry family is elaborated. An array denotes an
  916. unconstrained type.
  917.  
  918. type_of: unique name of parent sequence. 
  919. This is invariably a generated name. For the predef
  920. defined STRING type, the parent sequence is STRING itself.
  921. all sequences are arrays whose type is themselves.
  922.  
  923. signature: the pair :
  924.  
  925.         [ index-types, component-type]
  926.  
  927. where index_types is a tuple of type names.
  928.  
  929.  
  930. overloads: 
  931.  
  932. type_attr:  misc_type_attributes
  933.  
  934. NA_ATTRIBUTE:
  935. -------------
  936. An entry of this nature denotes a predefined attribute
  937. of the language.
  938. Many attributes are generic : they apply to classes of types.
  939.  
  940. type_of: either a predefined type, (INTEGER or STRING) or the 
  941. marker 'overloaded'. This indicates
  942. that the type returned by the attribute depends on the type of
  943. its arguments.
  944.  
  945. signature,overloads: not used 
  946.  
  947.  
  948. NA_BLOCK:    
  949. ---------
  950. There are three kinds of blocks, distinguished by their overloads values:
  951. block, loop or handler. A loop has alias defined, so all entries need
  952. full length symbol table entry.
  953. In SETL, the type_of field is used to hold the block type. In C we
  954. use special codes stored in the overloads field.
  955. Blocks are not used for separate compilation, so it is an error
  956. if one occurs.
  957.  
  958. signature: miscellaneous information.
  959.     unused externally
  960.  
  961. overloads: block type, one of the following
  962.  */
  963. #define BLOCK_BLOCK    0
  964. #define BLOCK_LOOP    1
  965. #define BLOCK_HANDLER    2
  966. /*
  967. Note that the use of overloads for NA_BLOCK is internal to adasem. This
  968. information need not be written out externally.
  969.  
  970.  
  971. NA_CONSTANT:    
  972. ------------
  973. Denotes a symbol table slot for a user-defined constant
  974. or for the result of evaluating a static expression.
  975.  
  976. type_of: specified type for constant.
  977.  
  978. signature: Node for expression
  979.  
  980. overloads: not used 
  981.  
  982. NA_ENTRY:    
  983. ---------
  984. denotes an entry object. 
  985.  
  986. type_of: points to an entry former. 
  987.  
  988. signature: the formalslist, and is identical
  989. to that of a subprogram. 
  990.  
  991. overloads: identical to that of a subprogram
  992.  
  993.  
  994. NA_ENTRY_FAMILY:    
  995. ----------------
  996. denotes an entry family object. This is a non-over-
  997. loadable entity, constructed as an array of entries. 
  998.  
  999. type_of: anonymous array type whose component is an entry-type.
  1000.  
  1001. signature: formal parameters
  1002.  
  1003. overloads: not used
  1004.  
  1005.  
  1006. NA_ENTRY_FORMER:    
  1007. ----------------
  1008. denotes the type of an entry object. Calls to entries
  1009. (rendez-vous) have the same syntax as procedure calls, and
  1010. named and default parameters are also present. 
  1011.  
  1012. type_of: task type in which it is declared (same as scope_of, in fact)
  1013. *    ??   As for procedures, the TYPE_OF an entry is the marker 'none'.
  1014.  
  1015. signature: the list of formals for the entry, and has the same format 
  1016. as that of a procedure.
  1017. An entry call does not return a value. 
  1018.  
  1019. overloads: not used
  1020.  
  1021.  
  1022. NA_ENUM:
  1023. --------
  1024. Denotes an enumeration type.
  1025.  
  1026. type_of: parent type, if derived, or the typename itself for 
  1027. BOOLEAN, CHARACTER, and non-derived enumerations.
  1028.  
  1029. signature: the range for the enumeration type in the format:
  1030.  
  1031.         ['range', low, high]
  1032.  
  1033. where low and high are the integer values for the first
  1034. and last enumeration literals of the type.
  1035.  
  1036. overloads: a map, from the literals to their POS in the type. 
  1037. By default the range of this map is dense
  1038. and 0-origined, but it can be modified by a representation
  1039. clause. This map is accessed by the macro literal_map.
  1040. It is represented in C as a tuple with element i being pointer to
  1041. string for literal, element i+1 being value of literal map for
  1042. the string.
  1043.  
  1044.  
  1045.  
  1046. NA_EXCEPTION:
  1047. -------------
  1048.  
  1049. NA_FUNCTION:    
  1050. ------------
  1051. identical to NA_PROCEDURE. 
  1052.  
  1053. type_of: the type which it returns.
  1054.  
  1055. signature:    same as for procedure.
  1056.  
  1057. overloads:    same as for procedure.
  1058.  
  1059.  
  1060. NA_FUNCTION_SPEC:    
  1061. -----------------
  1062.  
  1063. An entry is given this
  1064. nature after the corresponding subprogram specification
  1065. is processed. When the subprogram body is encountered
  1066. the specification is examined again, and if it coincides with
  1067. an existing symbol table slot, the _spec tag is removed.
  1068.  
  1069. signature:    same as for procedure
  1070.  
  1071. overloads:    same as for procedure
  1072.  
  1073. NA_GENERIC_FUNCTION_SPEC:
  1074. NA_GENERIC_PROCEDURE_SPEC:
  1075. NA_GENERIC_PACKAGE:    
  1076. ---------------------
  1077.  
  1078. Generic objects have the same organization as their non-generic
  1079. counterparts. The SIGNATURE of a generic entity has, in addition to
  1080. its non-generic purpose, the further role of holding the list of
  1081. generic parameters and the body of the generic object.
  1082.  
  1083. type_of: unused. 
  1084.  
  1085. signature:    The signature is a tuple with two elements:
  1086.         1) gen_list, a tuple of pairs, each consisting 
  1087.            of a symbol and a node.
  1088.         2) form_list, a tuple of symbols
  1089.  
  1090. overloads: not used
  1091.  
  1092. NA_GENERIC_PACKAGE:    
  1093. ---------------------
  1094.  
  1095.  
  1096. type_of: unused. 
  1097.  
  1098. signature:    A tuple with three elements:
  1099.         1) gen_list, a tuple of pairs, as for generic_procedure
  1100.         2) decl_node, a node.
  1101.         3) opt_priv_node, a node.
  1102.  
  1103. overloads: not used
  1104.  
  1105. NA_IN:
  1106. ------
  1107.  
  1108. type_of:    type of formal parameter
  1109.  
  1110. signature:    initial value (node) if there is one, else null node.
  1111.  
  1112. overloads:    not used.
  1113.  
  1114. NA_INOUT:    
  1115. ---------
  1116.  
  1117. type_of:    type of formal parameter
  1118.  
  1119. signature:    initial value (node) if there is one, else null node.
  1120.  
  1121. overloads:    not used.
  1122.  
  1123.  
  1124. NA_LABEL:    
  1125. ---------
  1126. An entry for a label requires only a single bit, indicating whether
  1127. the label has been defined.    
  1128.  
  1129. NA_LITERAL:    
  1130. -----------
  1131. an entry of this nature denotes an enumeration literal.
  1132.  
  1133. type_of: entry holds the unique name of the enumeration type
  1134. to which it belongs.
  1135.  
  1136. signature: is the same as that of a parameterless function, i.e. [].
  1137.  
  1138. overloads: same meaning as for operators
  1139.  
  1140. NA_NULL
  1141. -------
  1142. TBSL (almost certainly dead - does not occur in SETL)
  1143.  
  1144. NA_OBJ:     
  1145. -------
  1146. Denotes a symbol table slot for a program variable.
  1147.  
  1148. type_of: a unique name, namely that of a user-defined or 
  1149. internally generated type.
  1150.  
  1151. signature:    holds the initial value for fields of a record. Otherwise,
  1152.                 it is not used.
  1153.  
  1154. overloads:    not used
  1155.  
  1156. NA_OP:        
  1157. ------
  1158. An entry with this nature denotes a predefined operator in the
  1159. language.
  1160.  
  1161. type_of: for an operator is usually a generic marker
  1162. which indicates the family of types to which this operator can
  1163. apply. This marker obviates the need to introduce a separate
  1164. operator for each type derived from the predefined types. These
  1165. generic type marks are also given a symbol table slot. The
  1166. following are used :
  1167.  
  1168.        1) 'universal_integer' : for all arithmetic operators which apply
  1169.        to integers.
  1170.        2) 'universal_real'     : ditto for floating and fixed types.
  1171.        3) 'array_type'   : used for the (idiosyncratic) concatenation
  1172.           operator.
  1173.        4) 'order_type'   : for comparison operators.
  1174.       5) 'boolean type' : for boolean operators. This simplifies the
  1175.           handling of arrays of booleans and derived(!) booleans.
  1176.        6) 'string_type'  : for string literals, which overload any
  1177.           array of characters.
  1178.  
  1179.  
  1180.    We represent these in C as values of following global variables:
  1181.     gtm_universal_integer
  1182.     gtm_universal_real
  1183.     gtm_array_type
  1184.     gtm_order_type
  1185.     gtm_boolean_type
  1186.     gtm_string_type
  1187. */
  1188.  
  1189. /*
  1190.  
  1191. signature: follows the same format as the one for a subprogram. 
  1192. The canonical parameter names LEFT and RIGHT are not stored explicitly
  1193. but are known to an internal procedure order_arg_list in those rare
  1194. cases when an operator is used in functional notation with named
  1195. associatoins.
  1196. Note that this need not appear when writing externally.
  1197.  
  1198. overloads: has the same meaning as for subprograms. 
  1199. Given that operators are entered into the symbol
  1200. table during initialization, at the outermost scope, most ope-
  1201. rators in fact do not overload anything. For arithmetic ope-
  1202. rators however, we give different unique names to the integer
  1203. and floating point version of them.
  1204.  
  1205.  
  1206. */
  1207.  
  1208.  
  1209. /*
  1210.  
  1211. NA_OUT:        
  1212. -------
  1213.  
  1214. type_of:    type of formal parameter
  1215.  
  1216. signature: not used
  1217. Note however that as a byproduct of initializing nodes for arguments,
  1218. the signature may be a node, namely OPT_NODE.
  1219.  
  1220. NA_PACKAGE:    
  1221. -----------
  1222. designates a package or a package specification. 
  1223.  
  1224. type_of: not used
  1225.  
  1226. signature: not used
  1227.  
  1228. overloads: pointer to private symbol table with private declarations
  1229. of the package.
  1230.  
  1231. */
  1232.  
  1233. /*
  1234.  *    Private Declarations
  1235.  *
  1236.  * Access to entities declared in a package is through its declared map 
  1237.  * (when inside the package) or through its visible map, which holds only the
  1238.  * declarations in the visible part of the package specification.
  1239.  * The private declarations for the package are stored as a map
  1240.  * in its overloads entry, and installed in the symbol table on
  1241.  * entry to the package body (i.e. when compiling the body).
  1242.  * The    macro  private_decls(pack) accesses the private decls,
  1243.  * which are installed when compiling the body of the package,
  1244.  * and removed after the body.
  1245.  * Access to entities in the specification is
  1246.  * via the mapping VISIBLE. The domain of visible(p) is a sub-
  1247.  * set of that of declared(p).
  1248.  * The private declarations of the package are stored in a
  1249.  * separate structure, private_decls(p). These private decla-
  1250.  * rations are installed in the global symbol table when the
  1251.  * body of the package is compiled, and removed afterwards, so
  1252.  * that only the visible attributes remain accessible outside
  1253.  * of the package.
  1254.  * 
  1255.  * Note that in the C version, VISIBLE is not a separate map but
  1256.  * an attribute associated with each entry in a declared map.
  1257.  * alias: ??
  1258.  * -- pdecl.doc
  1259.  * In the C version, private_decls is represented as a pointer to a tuple.
  1260.  * The pointer is needed so we can expand the tuple as necessary.
  1261.  * Each odd entry is a symbol table pointer and is followed by 
  1262.  * a symbol table pointer to a symbol table information saved when
  1263.  * the declaration was installed (by private_decls_put).
  1264.  * 
  1265.  * private_decls is accessed by the
  1266.  * following procedures:
  1267.  * 
  1268.  *    Private_declarations    pdecl;
  1269.  *    Symbol    s1,s2;
  1270.  * 
  1271.  *    private_decls_new(n) - allocate new tuple for n symbols
  1272.  * 
  1273.  *    private_decls_put(pdecl,s1);
  1274.  *    Install s1 in pdecl if not yet present. Copy current symbol
  1275.  *    table field values for s1 into saved entry in pdecl.
  1276.  * 
  1277.  *    Symbol private_decls_get(pdecl,s1)
  1278.  *    Return entry in pdecl for s1 if present, (Symbol)0 otherwise.
  1279.  * 
  1280.  *    private_decls_swap(s1,s2)
  1281.  *    swaps symbol table blocks for s1 and s2.
  1282.  */
  1283. typedef struct Private_declarations_s 
  1284. {
  1285.     Tuple    private_declarations_tuple;    
  1286. } Private_declarations_s;
  1287. typedef Private_declarations_s    *Private_declarations;
  1288.  
  1289.  
  1290. typedef struct    Forprivate_decls {
  1291.     Tuple    forprivate_tup;
  1292.     int    forprivate_i;
  1293.     int    forprivate_n;
  1294. } Forprivate_decls;
  1295.  
  1296. #define FORPRIVATE_DECLS(s1,s2,pd,fp) \
  1297.      fp.forprivate_tup = (Tuple) (pd)->private_declarations_tuple; \
  1298.      fp.forprivate_n = tup_size(fp.forprivate_tup) ; \
  1299.       for (fp.forprivate_i=1; fp.forprivate_i<=fp.forprivate_n;) { \
  1300.     s1 = (Symbol) fp.forprivate_tup[fp.forprivate_i++]; \
  1301.     s2 = (Symbol) fp.forprivate_tup[fp.forprivate_i++];
  1302.  
  1303. #define ENDFORPRIVATE_DECLS(fp) }
  1304.  
  1305. /*
  1306.  
  1307. NA_PACKAGE_SPEC:
  1308. ----------------
  1309. overloads: not used
  1310. signature: not used
  1311.  
  1312. NA_PRIVATE_PART:
  1313. ----------------
  1314.  * 'private_part': for technical reasons, it is convenient to regard the
  1315.  *      private part of a package specification as a scope in its own
  1316.  *      right. This simplifies the segregation of private declarations
  1317.  *      from visible ones, and the detection of sundry semantic errrors
  1318.  *
  1319. overloads:    not used
  1320. signature:    not used
  1321.  
  1322. NA_PROCEDURE:    
  1323. -------------
  1324. Denotes a symbol table slot for a procedure subprogram.
  1325.  
  1326. type_of: holds the marker NULL (ie., a null pointer).
  1327.  
  1328. signature: describes the formal parameters of the procedure.
  1329. It is a tuple of symbol table pointers to formal parameter entries 
  1330. (of type na_in, na_out, or na_inout).
  1331.  
  1332. overloads: the set of procedures with the
  1333. same name (source identifier, that is) which appear in the
  1334. current lexical scope, and which are
  1335. not hidden by the current entry. This set is built when the
  1336. procedure specification is processed (See procedure : chain-
  1337. overloads in the semantic actions) and is central to the
  1338. overload resolution mechanism.
  1339. overloads(id) always includes -id- itself.
  1340.  
  1341. If the procedure is the only visible instance of the name,
  1342. (i.e. it overloads no other identifier) then the overloads
  1343. entry is the singleton set containing its own name.
  1344.  
  1345. alias: ??
  1346.  
  1347. declared: ??
  1348.  
  1349.  
  1350. NA_PROCEDURE_SPEC:    
  1351. ------------------
  1352.  
  1353. An entry is given this nature after the corresponding subprogram
  1354. specification is processed. When the subprogram body is encountered the
  1355. specification is examined again, and if it coincides with an existing
  1356. symbol table slot, the _spec tag is removed. Apart from generic objects,
  1357. all remaining types of entries denote type entities. 
  1358.  
  1359. signature:    same as for procedure.
  1360.  
  1361. overloads:    same as for procedure.
  1362.  
  1363. Other fields same as procedure spec.
  1364.  
  1365. NA_TYPE:
  1366. --------
  1367. This denotes an entry for a new, or derived type
  1368. from one of the numeric types 'INTEGER', 'FLOAT',
  1369. or '$FIXED', or from another numeric type, or
  1370. the error type 'any'.
  1371. All such entries have all symbol fields, including alias, defined.
  1372.  
  1373. type_of: unique name of the type from which the current one is derived.
  1374.  
  1375. signature: the constraint (see 'subtype' below).
  1376.  
  1377. Private and incomplete type declarations produce type
  1378. entries whose type_of field is 'private','limited private'
  1379. or 'incomplete' respectively.
  1380.  
  1381. overloads: The map 'misc_type_attributes' collects various useful predi-
  1382. cates on types, in particular composite and generic types.
  1383. This information is kept in the field type_attr.
  1384.  
  1385. In C, misc_type_attributes can be represented as a byte, assigning
  1386. a bit for each of the necessary attributes:
  1387. flag TA_ISPRIVATE is used only when writing out files in C format
  1388. to flag the case of a private or limited private type. This is determined
  1389. in SETL by a symbol having a TYPE_OF corresponding to 'private' or
  1390. 'limited private', and in C by TYPE_OF being symbol_private or symbol_limited
  1391. private. For such symbols we set TA_ISPRIVATE when writing the symbol to
  1392. indicate that the signature has the same format as for a record (na_record),
  1393. even though the nature is not necessarily na_record.
  1394.  
  1395. */
  1396.  
  1397. #define TA_ISPRIVATE  1
  1398. #define TA_INCOMPLETE 2
  1399. #define TA_LIMITED    4
  1400. #define TA_LIMITED_PRIVATE    8
  1401. #define TA_PRIVATE        16
  1402. #define TA_OUT            32
  1403. /* GENERIC corresponds to '$generic' in SETL */
  1404. #define TA_GENERIC        64
  1405. /* CONSTRAIN corresponds to '$constrain' in SETL */
  1406. #define TA_CONSTRAIN        128
  1407.  
  1408. /*
  1409.  
  1410.  
  1411. NA_RECORD:
  1412. ----------
  1413. Denotes a record type.
  1414.  
  1415. type_of: the type name itself.
  1416.  
  1417. signature: a tuple formatted as follows (in SETL):
  1418.  
  1419.         [ [invariant_part, variant_part], discriminant_list ,
  1420.                         declared_map, discr_decl_tree ]
  1421.  
  1422. the discriminant list is [] for a record without discrimants.
  1423. In the above, invariant_part and variant_part refer to AST nodes.
  1424.  
  1425. In C version, signature is quintuple as follows:
  1426.     [ invariant_part, variant_part, discriminant_list, declared_map,
  1427.         discr_decl_tree]
  1428. invariant_part, variant_part and discr_decl_tree are nodes.
  1429. discriminant list is tuple of symbols.
  1430. The declared_map is the (declared) map from selector names
  1431. to the unique names which have been assigned to them.
  1432. (NOTE: This is redundant if we keep declared for record)
  1433.  
  1434. Note that this is initialized in process_discr in ch 3.
  1435.  
  1436. overloads:  not used (was misc_type_attributes)
  1437.  
  1438. type_attr:  misc_type_attributes
  1439.  
  1440.  
  1441. NA_SUBTYPE:
  1442. -----------
  1443. This denotes an entry for a declared subtype, or for a
  1444. range descriptor which has been promoted to a subtype.
  1445.  
  1446. type_of: unique name of the type of which the current one is a subtype, 
  1447. i.e. its base type.
  1448.  
  1449. signature: the constraint which defines the subtype. 
  1450. For numeric types, the constraint has one of the
  1451. following formats :
  1452.  
  1453.         ['range' low, high]        for integer subtypes.
  1454.  
  1455.         ['digits', low, high, digits]    for floating types.
  1456.  
  1457.         ['delta', low, high, delta,small]    for fixed types.
  1458.  
  1459. In each case, -low- and -high- are the bounds of the subytpe.
  1460. digits is a SETL integer, delta is a SETL floating point.
  1461. Both of them have their standard Ada meaning .
  1462. Components other than the first are nodes.
  1463.  
  1464. Add CONSTRAINT_DISCR (ds 14 aug) to correspond to 'discr' case
  1465. in SETL. For this type numeric_constraint_value[0] will be tuple with
  1466. list of discriminant values. 
  1467. This will be referenced as numeric_constraint_discr.
  1468.  
  1469. Add CONSTRAINT_ARRRY (ds 1 jan 84) to correspond to constrained aray
  1470. case. For this type the SETL signature has the same form as form an
  1471. array type - a pair whose first component is a tuple of symbols and
  1472. whose second component is a symbol. 
  1473. In C we keep the signature as a tuple, using CONSTRAINT_ARRAY only when
  1474. writing and reading the ais file in c format.
  1475.  
  1476. Add CONSTRAINT_ACCESS for subtypes of access types. In SETL, this was
  1477. just the designated type. Here, for uniformity of subtypes, we keep
  1478. it as a constraint (a tuple whose first element is CONSTRAINT_ACCESS, 
  1479. and second is the designated type).  The macro designated_type 
  1480. has been changed to reflect this.
  1481.  
  1482. In C we represent the constraint as the following structure:
  1483. */
  1484. #define CONSTRAINT_RANGE 0
  1485. #define CONSTRAINT_DIGITS 1
  1486. #define CONSTRAINT_DELTA 2
  1487. #define CONSTRAINT_DISCR 3
  1488. #define CONSTRAINT_ARRAY 4
  1489. #define CONSTRAINT_ACCESS 6
  1490.  
  1491. #define numeric_constraint_kind(p) p[1]
  1492. #define numeric_constraint_low(p) p[2]
  1493. #define numeric_constraint_high(p) p[3]
  1494. #define numeric_constraint_digits(p) p[4]
  1495. #define numeric_constraint_delta(p) p[4]
  1496. #define numeric_constraint_small(p) p[5]
  1497. #define numeric_constraint_discr(p) p[2]
  1498.  
  1499. /* new instances of above allocated by new_constraint(type) */
  1500. /*
  1501.    for record subtypes, the constraint as the format :
  1502.         ['discr', list of discriminant values]
  1503. For records we also need the discriminant map. In SETL this is a map
  1504. from symbols to nodes. The only operations used are initialization,
  1505. assignment, retrieval and interation, so in C we keep this map as a tuple
  1506. with successive pairs of elements representing the domain (Symbol) and
  1507. range (Node) values.  The following procedures are used to access the
  1508. map:
  1509.     Node discr_map_get(dmap, sym);
  1510.         Symbol  sym;
  1511.     retrieve value of map for symbol sym.
  1512.  
  1513.     Tuple discr_map_put(dmap,sym,nod)
  1514.        Symbol  sym; Node nod;
  1515.     set value of map dmap for symbol sym to node nod.
  1516.  
  1517. Note that symbols corresponding to private types have a signature of
  1518. the same form as for a record; see discussion of TA_ISPRIVATE above.
  1519.  
  1520. overloads: field present, but not used.
  1521.  
  1522. declared: not used
  1523.  
  1524. alias: yes, for all types, the root type
  1525.  
  1526. */
  1527.  
  1528. /*
  1529.  
  1530. NA_TASK_OBJ    
  1531. -----------
  1532. Denotes a task type. A task object is either an object of
  1533. task type, or (in the case of a task family) an array of
  1534. objects of task type. A task contains declarations for
  1535. entries. Access is obtained by means of the -declared- map for
  1536. the task.
  1537.  
  1538. type_of: task type
  1539. signature: not used
  1540. overloads: not used
  1541. declared: defined
  1542.  
  1543. NA_TASK_OBJ_SPEC
  1544. ----------------
  1545.  
  1546. NA_TASK_TYPE:    
  1547. -------------
  1548. Same as NA_TASK.
  1549.  
  1550. NA_TASK_TYPE_SPEC
  1551. -----------------
  1552. Same as NA_TASK_TYPE.
  1553.  
  1554.  
  1555. NA_VOID
  1556. -------
  1557. TBSL
  1558. A symbol of this type is
  1559. generated for the symbol "$used". It has as signature a tuple of symbols:
  1560.     signature:    tuple of symbols
  1561. corresponding to the macro use_declarations in SETL.
  1562.  
  1563. */
  1564.  
  1565.  
  1566.  
  1567. /*
  1568.         DECLARED definitions and declarations
  1569.  
  1570.  
  1571. In the SETL version, program identifiers are related to unique
  1572. names using a global map DECLARED. Every lexical
  1573. scope corresponds to an entry in DECLARED. In turn, this entry is a
  1574. map from source identifiers to their unique names in that scope.
  1575.  
  1576.      DECLARED : scope-name ->  (map : identifier -> unique-name )
  1577.  
  1578. The scope manipulation routines and the name resolution routines
  1579. revolve around DECLARED. In the SETL code, access is typically via
  1580.     DECLARED(SCOPE_OF(name))(identifier)
  1581.  
  1582. In C, each symbol table entry has a field scope_of that gives the symbol
  1583. table entry of the scope for the entry. The declared field of the entry
  1584. for the scope is a pointer to the declared map from identifiers to
  1585. symbol table entries. Since access to the declared map involves a hashed
  1586. lookup, we will access the map using procedures (or macros that
  1587. ultimately invoke procedures). For example, SETL code 
  1588.     DECLARED(s)(id)
  1589. will become
  1590.     dcl_get(s,id)
  1591. for retrievial, or
  1592.     dcl_put(s,id,sym)
  1593. or
  1594.     dcl_put_vis(s,id,sym,vis)
  1595. to explicitly set visibility: dcl_put(s,id,sym) is same as
  1596.     dcl_put_vis(s,id,sym,TRUE);
  1597. for assignment,where s will often have one of the forms
  1598.     scope_name    or    scope_of(name)
  1599.  
  1600. Our intent is that, as much as possible, the existing SETL code can
  1601. be translated to C using dcl_get and dcl_put, using a 'paging' algorithm
  1602. to bring in names from other compilation units, possibly on library files,
  1603. in a manner transparent to most of the code. This paging process will involve
  1604. marking names as one of the following:
  1605.     installed    symbol table entry available
  1606.     not installed    name and location known, but symbol table entry
  1607.             not yet installed.
  1608. An identifer that is not installed will have an indication of the compilation
  1609. unit and 'file address' of the information needed to install the name.
  1610. Installation consists of converting the external 'file address' to an
  1611. internal pointer.
  1612.  
  1613. Note that map VISIBLE maintained in the SETL version is represented in 
  1614. the C version by the attribute is_visible associated with an entry
  1615. in a declared map.
  1616.  
  1617. */
  1618.  
  1619. typedef struct Declaredmap_s
  1620. {
  1621.     short        dmap_curlen;    /* current number of elements */
  1622.     short        dmap_maxlen;    /* maximum number of elements */
  1623.     struct Dment    *dmap_table;    /* pointer to entry list */
  1624.  } Declaredmap_s;
  1625.  
  1626. /* Each entry in the hash table is a pointer to a declared map entry */
  1627.  
  1628. typedef struct Dment
  1629. {
  1630.     struct {
  1631. #ifdef IBM_PC
  1632. /* avoid overlaying on PC, due to bad generated code  ds 4-26-86 */
  1633.     unsigned    dment_idnum ;   /* source identifier number */
  1634.     unsigned    dment_visible ;  /* non-zero if visible */
  1635. #else
  1636.     unsigned    dment_idnum : 15;   /* source identifier number */
  1637.     unsigned    dment_visible : 1;  /* non-zero if visible */
  1638. #endif
  1639.     } dment_i;
  1640.     Symbol        dment_symbol;        /* symbol table pointer */
  1641. }  Dment;
  1642.  
  1643. /*
  1644. dment_id is the character string for the source identifier. dment_hash
  1645. is the hash code of the string. This is     kept so that the hash table
  1646. size can be changed as the map grows without avoiding the need to rehash
  1647. all the strings. dment_next is a pointer to the next entry on the hash
  1648. chain, or NULL for the end of a chain. dment_symbol is a symbol table
  1649. pointer for an installed name, or NULL if the name not yet installed.
  1650. dment_install is a boolean, initially FALSE, that is set when the
  1651. identifier has been installed in the symbol table. Note that it may be
  1652. possible to avoid the use of this bit and just say a symbol is not
  1653. installed if dment_symbol is NULL. dment_file and dment_fileoff are the
  1654. file identifier and file offset; the details of these have to be worked
  1655. out. 
  1656. */
  1657.  
  1658. /* A tentative list of the procedures that are used to access a declared
  1659. map is as follows:
  1660.  
  1661. Declaredmap dcl_new(nh)     int nh;
  1662.   initializes declared map with nh hash headers
  1663.   (zero may be given, in which case default values
  1664.   are taken).
  1665.  
  1666. dcl_free(dmap)    Declaredmap dmap;
  1667.   free space occupied by declared map dmap.
  1668.  
  1669. Symbol dcl_get(dmap,s)    Declaredmap dmap; char * s;
  1670.   return current value of declared map dmap for string s, or NULL
  1671.   if map not defined for s.
  1672.  
  1673. Symbol dcl_get_vis(dmap,s)    Declaredmap dmap; char * s;
  1674.   return current value of declared map dmap for string s, or NULL
  1675.   if map not defined for s. This returns current value only if it
  1676.   is visible.
  1677.  
  1678.  
  1679.  
  1680. dcl_put_vis(dmap,str,sym,vis) Declaredmap dmap; char *str; Symbol sym; int vis;
  1681.   define value of declared map dmap for string s to be symbol s.
  1682.   This sets visible attribute for entered sym to vis.
  1683.  
  1684. dcl_put(dmap,str,sym) ...
  1685.   same as dcl_put_vis(dmap,str,sym,TRUE).
  1686.  
  1687. dcl_undef(dmap,str) Declaredmap dmap, char *str;
  1688.   undefine declared map dmap for string s; i.e., remove entry from map
  1689.   if present.
  1690.  
  1691. The form of an iteration over a declared map is:
  1692.   FORDECLARED(str,sym, dmap, dmapiv)
  1693. which iterates over declared map dmap using dmapiv to control iteration.
  1694. For each pass, str is set to identifier, sym to symbol table pointer.
  1695.  
  1696.   Fordeclared dmapiv;
  1697.   Declaredmap    dmap;
  1698.   char *str; Symbol sym;
  1699.   FORDECLARED(str,sym,dmap,dmapiv)
  1700.  
  1701.   ENDFORDECLARED(dmapiv)
  1702.  
  1703. Within a FORDECLARED iteration, the macro IS_VISIBLE may used to get
  1704. visibility status of the current variable, by
  1705.     IS_VISIBLE(dmapiv).
  1706. ISVISIBLE may be used on the left hand side to change visibility,
  1707.     IS_VISIBLE(dmapiv) = 0    .
  1708. */
  1709. typedef struct    Fordeclared {
  1710.     Declaredmap fordeclared_map;
  1711.     unsigned short    fordeclared_i;
  1712.     unsigned short    fordeclared_n;
  1713.     struct Dment *fordeclared_dment;
  1714. } Fordeclared;
  1715.  
  1716. extern char *dstrings;
  1717.  
  1718. #define FORDECLARED(str,sym,dmap,iv) \
  1719.     iv.fordeclared_map = dmap; \
  1720.     iv.fordeclared_n = iv.fordeclared_map->dmap_curlen;\
  1721.     iv.fordeclared_dment = iv.fordeclared_map->dmap_table; \
  1722.     for (iv.fordeclared_i=0; iv.fordeclared_i<iv.fordeclared_n; \
  1723.     (iv.fordeclared_i++,iv.fordeclared_dment++)) { \
  1724.       str = dstrings + iv.fordeclared_dment->dment_i.dment_idnum;\
  1725.       sym = iv.fordeclared_dment->dment_symbol;\
  1726.  
  1727. #define ENDFORDECLARED(iv) }
  1728. #define IS_VISIBLE(iv) iv.fordeclared_dment->dment_i.dment_visible 
  1729. #define SETDECLAREDVISIBLE(iv,n) \
  1730.     IS_VISIBLE(iv) = n;    
  1731. /*
  1732. The form of an iteration over a declared map, visiting only the visible
  1733. entries, is:
  1734.   FORVISIBLE(str,sym, dmap, dmapiv)
  1735. which iterates over declared map dmap using dmapiv to control iteration,
  1736. processing only visible entries.
  1737. For each pass, str is set to identifier, sym to symbol table pointer.
  1738.  
  1739.   Fordeclared dmapiv;
  1740.   Declaredmap    dmap;
  1741.   char *str; Symbol sym;
  1742.   FORVISIBLE(str,sym,dmap,dmapiv)
  1743.  
  1744.   ENDFORVISIBLE(dmapiv)
  1745.  
  1746.  
  1747. */
  1748. #define FORVISIBLE(str,sym,dmap,iv) \
  1749.     FORDECLARED(str,sym,dmap,iv) \
  1750.         if (IS_VISIBLE(iv)==0) continue;
  1751.  
  1752.  
  1753. #define ENDFORVISIBLE(iv) }
  1754.  
  1755. /* Declarations for use by evalstat. 
  1756.  * Values returned by evalstat are as follows:
  1757.  */
  1758.  
  1759. typedef struct Const_s    *Const;
  1760. typedef struct Const_s {
  1761.     int    const_kind;
  1762.     union    {
  1763.         int    const_int;
  1764.         int    *const_uint;
  1765.         double    const_real;
  1766.         char    *const_str;
  1767.         Rational    const_rat;
  1768.         long    const_fixed;
  1769.         } const_value;
  1770.     } Const_s;
  1771.  
  1772. #ifdef IVALUE
  1773. /* Const should be ivalue. Define both until Sem changed */
  1774. typedef struct Ivalue_s *Ivalue;
  1775. typedef struct Ivalue_s {
  1776.     int    ivalue_kind;
  1777.     union    {
  1778.         int    ivalue_int;
  1779.         int    *ivalue_uint;
  1780.         double    ivalue_real;
  1781.         char    *ivalue_str;
  1782.         Rational    ivalue_rat;
  1783.         long    ivalue_fixed;
  1784.         } ivalue_value;
  1785.     } Ivalue_s;
  1786. #endif
  1787. /* kinds for const_kind */
  1788. #define CONST_OM    0
  1789. #define CONST_INT    1
  1790. #define CONST_REAL    2
  1791. #define CONST_STR    3
  1792. #define CONST_RAT    4
  1793. #define CONST_CONSTRAINT_ERROR 5
  1794. #define CONST_UINT    6
  1795. #define CONST_FIXED    7
  1796.  
  1797. /* predicates for const_kind */
  1798. #define is_const_om(c) ((c)->const_kind == CONST_OM)
  1799. #define is_const_int(c) ((c)->const_kind == CONST_INT)
  1800. #define is_const_real(c) ((c)->const_kind == CONST_REAL)
  1801. #define is_const_str(c) ((c)->const_kind == CONST_STR)
  1802. #define is_const_rat(c) ((c)->const_kind == CONST_RAT)
  1803. #define is_const_constraint_error(c) ((c)->const_kind == CONST_CONSTRAINT_ERROR)
  1804. #define is_const_uint(c) ((c)->const_kind == CONST_UINT)
  1805. #define is_const_fixed(c) ((c)->const_kind == CONST_FIXED)
  1806.  
  1807. /* kinds for const_kind */
  1808. #ifdef IVALUE
  1809. /* CONST_ should be IVALUE_. Define both until convert Sem */
  1810. #define IVALUE_OM    0
  1811. #define IVALUE_INT    1
  1812. #define IVALUE_REAL    2
  1813. #define IVALUE_STR    3
  1814. #define IVALUE_RAT    4
  1815. #define IVALUE_CONSTRAINT_ERROR 5
  1816. #define IVALUE_UINT    6
  1817. #define IVALUE_FIXED    7
  1818. #endif
  1819.  
  1820. /* Macros to access values of a Const */
  1821. #define INTV(op) (op)->const_value.const_int
  1822. #define UINTV(op) (op)->const_value.const_uint
  1823. #define REALV(op) (op)->const_value.const_real
  1824. #define RATV(op) (op)->const_value.const_rat
  1825. #define FIXEDV(op) (op)->const_value.const_fixed
  1826.  
  1827.     
  1828. /* The SETL maps rename_map and type_map are maps from symbols
  1829.  * to symbols. In the C version these are kept as type Symbolmap,
  1830.  * currently represented using a tuple map, i.e.,  a tuple with
  1831.  * successive pairs of domain values followed by the range value.
  1832.  */
  1833.  
  1834. typedef struct Symbolmap_s 
  1835. {
  1836.     Tuple    symbolmap_tuple;    
  1837. } Symbolmap_s;
  1838. typedef Symbolmap_s    *Symbolmap;
  1839. /* and is accessed using the following procedures (defined in 12.c): */
  1840.  
  1841. /*
  1842. Iteration over symbolmaps is done as follows:
  1843.  */
  1844. typedef struct    Forsymbol {
  1845.     Tuple    forsymbolmap_tuple;
  1846.     int    forsymbolmap_i;
  1847.     int    forsymbolmap_n;
  1848. } Forsymbol;
  1849.  
  1850. #define FORSYMBOL(s1,s2,pd,fp) \
  1851.      fp.forsymbolmap_tuple = (Tuple) (pd)->symbolmap_tuple; \
  1852.      fp.forsymbolmap_n = tup_size(fp.forsymbolmap_tuple) ; \
  1853.       for (fp.forsymbolmap_i=1; fp.forsymbolmap_i<=fp.forsymbolmap_n;) { \
  1854.     s1 = (Symbol) fp.forsymbolmap_tuple[fp.forsymbolmap_i++]; \
  1855.     s2 = (Symbol) fp.forsymbolmap_tuple[fp.forsymbolmap_i++];
  1856.  
  1857. #define ENDFORSYMBOL(fp) }
  1858.  
  1859. typedef struct Nodemap_s 
  1860. {
  1861.     Tuple    nodemap_tuple;    
  1862. } Nodemap_s;
  1863. typedef Nodemap_s    *Nodemap;
  1864. /*
  1865.  *T+ UTILITY MACROS FOR SEMANTIC MODULES.
  1866.  *S+ Global macros for the use of all modules:
  1867. */
  1868.  
  1869. /* We define the utility macros in lower case since that is the
  1870.  * case used in the SETL source.
  1871.  */
  1872.  
  1873. /* macro find;    assert exists        endm; */
  1874. #define find ???
  1875.  
  1876. /* macro top(x);    x(#x)            endm; */
  1877.  
  1878. /* *S+ Macros for manipulation of the AST. */
  1879.  
  1880. /*macro is_empty(node);     (node=[])      endm ; */
  1881. #define is_empty(node) ((int)node[0] == 0)
  1882.  
  1883. /* macro attribute_name(node) ; ;N_VAL(N_AST(node)(1))    endm; */
  1884. /* In C this returns integer attribute code stored in ast1 node of  node */
  1885. /* this returns integer not string */
  1886. #define attribute_name(node) N_VAL(N_AST1(node))
  1887.  
  1888. /* In C we define attribute_kind to return integer attribute code */
  1889. #define attribute_kind(node) N_VAL(N_AST1((node)))
  1890.  
  1891. /*
  1892. macro SYMBTAB(name);
  1893.     [NATURE(name),TYPE_OF(name),SIGNATURE(name),OVERLOADS(name)] endm;
  1894. */
  1895.  
  1896. /*
  1897.  * For library and stub manipulation, the scope_of map must also
  1898.  * be saved and restored. The following macro is usedfor that purpose.
  1899.  */
  1900.  
  1901. /*
  1902. macro SYMBTABF(name) ;
  1903.     [NATURE(name), TYPE_OF(name), SIGNATURE(name), OVERLOADS(name),
  1904.      SCOPE_OF(name), ALIAS(name) ]
  1905. endm ;
  1906. */
  1907.  
  1908. /*
  1909.  * The following is a lexical macro which converts a double-quoted
  1910.  * character which appears as a designator, into a one-character
  1911.  * string. This distinction is imposed by the need to differentiate
  1912.  * the literal    a  from the character  "a"  when they appear in an
  1913.  * enumeration literal, but nowhere else.
  1914.  */
  1915.  
  1916. /*macro char_to_name(desig) ;
  1917. (if # desig = 3 and desig(1) = '"' and desig(3) = '"' then
  1918.       desig(2) else desig end)
  1919. endm ;
  1920. */
  1921.  
  1922. /* *S+ Macros for accessing type information. */
  1923.  
  1924. /* macro root_type(type_mark) ;     ALIAS(type_mark) endm ;  $$ES68 */
  1925. #define root_type(type_mark) ((type_mark)->alias)
  1926.  
  1927. /*
  1928. macro index_types(array_type) ;
  1929.     signature(array_type)(1) endm ;
  1930. */
  1931. #define index_types(array_type) ((Tuple) ((array_type)->signature)[1])
  1932.  
  1933. /*
  1934.  * macro component_type(array_type) ;
  1935.  *  signature(array_type)(2)
  1936.  * endm ;
  1937.  */
  1938. #define component_type(array_type) ((Symbol) ((array_type)->signature)[2])
  1939.  
  1940. /*
  1941. macro no_dimensions(array_type) ;
  1942.     (#index_types(array_type))
  1943. endm ;
  1944. */
  1945.  
  1946. /*
  1947. macro index_type(array_type) ;
  1948.     (index_types(array_type)(1))
  1949. endm ;
  1950.  */
  1951. #define index_type(array_type)    ((Tuple) (index_types(array_type))[1])
  1952.  
  1953. /*
  1954. macro literal_map(enumeration) ;
  1955.     overloads(enumeration)
  1956. endm ;
  1957.  */
  1958. #define literal_map(enumeration) ((enumeration)->overloads)
  1959.  
  1960. /* macro record_declarations(record); signature(record) endm ; */
  1961. #define record_declarations(record) ((record)->signature)
  1962.  
  1963. /* In C, will have the following reference a single quadruple
  1964.    ds    14 aug
  1965.  */
  1966. /* macro all_components(record) ;     signature(record)(1) endm ; */
  1967. #ifdef TBSN
  1968. -- all_components should be dead    ds 14 aug
  1969. #define all_components(record) (((record)->signature)[1])
  1970. #endif
  1971.  
  1972. /* the macros for records that access components of the signature
  1973.  * cannot be written on the left hand side due to use of (Tuple)
  1974.  * cast to get indexing right. The left hand case is done by
  1975.  * explicit assignment; see record_decl(3b.c) and process_discr (3b.c).
  1976.  * ds 31-dec-84
  1977.  */
  1978. /* macro discriminant_list(record) ;  signature(record)(2) endm ; */
  1979. #define discriminant_list(record) ((Tuple) ((record)->signature)[3])
  1980.  
  1981. /* macro invariant_part(record) ;     all_components(record)(1) endm ;*/
  1982. #define invariant_part(record) ((Tuple) ((record)->signature)[1])
  1983.  
  1984. /* macro variant_part(record) ;       all_components(record)(2) endm ; */
  1985. #define variant_part(record)    ((Tuple) ((record)->signature)[2])
  1986.  
  1987. /* macro declared_components(record); signature(record)(3) endm ; */
  1988. /* The value returned by declared_components is a declared map */
  1989. #define declared_components(record) ((Tuple) ((record)->signature)[4])
  1990.  
  1991. /* TBSLshould this be four or five  ds 14 aug */
  1992. /* macro discr_decl_tree(record);     signature(record)(4) endm ; */
  1993. #define discr_decl_tree(record) ((Tuple) ((record)->signature)[5])
  1994. /*
  1995. macro has_discriminants(record) ;
  1996.       (discriminant_list(root_type(record)) /= [])           endm ;
  1997.  */
  1998.  
  1999. #define has_discriminants(record) \
  2000.     (discriminant_list(root_type(record)) != (Tuple) 0  &&   \
  2001.      tup_size(discriminant_list(root_type(record))) != 0)
  2002.  
  2003.  
  2004. /*
  2005. macro designated_type(access_type) ;
  2006.             (signature(access_type))         endm ;
  2007. */
  2008. /* In the C version, the signature of a subtype of an access type is a
  2009.  * tuple whose first element is CONSTRAINT_ACCESS, and whose second
  2010.  * is the designated type symbol
  2011.  */
  2012. #define designated_type(access_type)                      \
  2013.     (((NATURE(access_type)==na_subtype)                  \
  2014.         ? (Symbol)((access_type)->signature)[2]          \
  2015.         : (Symbol)((access_type)->signature) ))
  2016.  
  2017. /*
  2018. macro is_range_attribute(e) ;
  2019.      (is_tuple(e) and e(1) = '''' and e(2) = 'RANGE')         endm ;
  2020. */
  2021.  
  2022. /* macro label_status(lab) ; signature(lab)             endm ; */
  2023. #define label_status(lab) ((lab)->signature)
  2024.  
  2025. /* default_expr has a node as its value (ds 15 may) */
  2026. /* macro default_expr(nam) ; signature(nam)             endm ;*/
  2027. #define default_expr(nam) ((nam)->signature)
  2028.  
  2029. #define formal_decl_tree(proc_name)  ((proc_name)->init_proc)
  2030.    /* formal_decl_tree stores the formals subtree for subsequent conformance
  2031.     * checks. It is defined for a subprogram_spec only, and therefore
  2032.     * overlays the init_proc fields used during code generation .
  2033.     */
  2034.  
  2035. /* *S+ Macros for scope manipulation. */
  2036.  
  2037. /* *$BB5 */
  2038. /*
  2039. macro init_scope_info ;
  2040.     ['STANDARD#0', '', ['STANDARD#0', 'UNMENTIONABLE#0'], [],
  2041.      ['ASCII'], ''
  2042.     ]
  2043. endm;
  2044. */
  2045.  
  2046. /*
  2047. macro is_comp_unit ;    (#scope_st = 0)         endm ;
  2048.  
  2049. macro scope_info ;
  2050.     [scope_name, prefix, open_scopes, used_mods, vis_mods, suffix]
  2051. endm ;
  2052. */
  2053.  
  2054.  
  2055. /* make c macro name upper case since no arguments*/
  2056. #define IS_COMP_UNIT (tup_size(scope_st)==0)
  2057.  
  2058.  /*S+ Miscellaneous type predicates.*/
  2059. /*macro is_access(name) ;
  2060.     (NATURE(root_type(name)) = na_access)          endm ; 
  2061. */
  2062. /* is_access now a procedure in the C version (smisc.c) */
  2063.  
  2064. /*macro is_identifier(name) ; is_string(name)    endm ; */
  2065. /*
  2066. Make this a procedure int is_identifier();*/
  2067.  
  2068. /*macro is_literal(name) ; nature(name) = 'literal'      endm ; */
  2069. #define is_literal(name) (NATURE((name)) == na_literal)
  2070.  
  2071. /*macro is_overloaded ; (is_set(name))      endm ; */
  2072. /* this is field N_OVERLOADED in C version */
  2073.  
  2074. /*  macro is_constant(name) ;
  2075.     (is_identifier(name) and nature(name) = 'constant') endm ;
  2076. */
  2077. /* In C is_identifier for symbol is just test that not null */
  2078. #define is_constant(name) ((name)!=(Symbol) 0 && NATURE((name))== na_constant)
  2079.  
  2080. /*macro is_proc(proc_name) ;
  2081.     nature(proc_name) in
  2082.      {'procedure', 'function','generic_procedure', 'generic_function'} endm;
  2083. */
  2084. /*
  2085. #define is_proc(proc_name) ( (TMP := nature(proc_name) == na_procedure ? 
  2086. TRUE : (TMP == na_function || TMP == na_generic_procedure \
  2087.   || TMP == na_generic function) ? TRUE : FALSE ) )
  2088. */
  2089.  
  2090. /*macro is_anonymous(typ) ; (original_name(typ) =='') endm ;*/
  2091. /* in C anonymous types are given an original name beginnning with & */
  2092. #define is_anonymous(typ)  (*(ORIG_NAME(typ)) == '&')
  2093.  
  2094. /*macro is_first_named_subtype(typ);  (is_anonymous(base_type(typ))) endm;*/
  2095.  
  2096. /* macro is_array(typ) ;  (nature(base_type(typ)) = 'array')   endm ; */
  2097. #define is_array(typ) (NATURE(base_type(typ)) == na_array)
  2098.  
  2099.  /**$PK3 ES118 */
  2100. /*
  2101. macro is_formal(id) ;  (nature(id) in ['in', 'out', 'inout']) endm ;
  2102. */
  2103. #define is_formal(id) (NATURE(id)==na_in || NATURE(id)==na_out     \
  2104.             || NATURE(id)==na_inout)
  2105.  
  2106. /*
  2107. macro is_generic(scope ; nat) ;
  2108.   ((nat:=nature(scope)) /= om and match(nat,'generic_') /= om)
  2109. endm ;
  2110. */
  2111.  
  2112. /* macro misc_type_attributes(type_mark) ;
  2113.                 overloads(type_mark)        endm;
  2114. */
  2115. /* In C misc_type_attributes are kept in separate field */
  2116. #define misc_type_attributes(type_mark) TYPE_ATTR(type_mark)
  2117.  
  2118. /*
  2119. macro private_dependents(type_mark) ;                 $$ES132
  2120.         misc_type_attributes(type_mark)            endm;
  2121. */
  2122. /* In C, private_dependents is kept in overloads field 
  2123.  */
  2124. #define private_dependents(type_mark)    OVERLOADS(type_mark)
  2125.  
  2126. /* macro private_decls(package);    overloads(package) endm; */
  2127.  
  2128. /* this yields a tuple    ds 25 jul */
  2129. #define private_decls(package) OVERLOADS(package) 
  2130.  
  2131. /*
  2132.  *$ES48
  2133. macro use_declarations(package) ;
  2134.     signature(declared(package)('$used'))            endm;
  2135. */
  2136. /* Since use_declarations appears on left hand side - we avoid
  2137.  * defining a macro for it in C (at least for now)    ds 4 aug 
  2138.  */
  2139. #ifdef TBSN
  2140. #define use_declarations(package) \
  2141.     SIGNATURE(dcl_get(DECLARED(package),"$used"))
  2142. #endif
  2143.  
  2144.  
  2145. /*
  2146. macro is_anonymous_task(name) ;
  2147.     (is_task_type(name) and 'task_type:' in original_name(name))
  2148. endm ;
  2149. */
  2150. /* make a procedure in C (by not defining as macro!) */
  2151.  
  2152. /*
  2153. macro is_integer_type(x) ;
  2154. (x in {'INTEGER', 'SHORT_INTEGER', 'LONG_INTEGER', 'universal_integer'})
  2155. endm ;
  2156. */
  2157.  
  2158. /*
  2159.  * The following macro is used by cross-reference making statements.
  2160.  * spans(node) is either [l_span] or [l_span, r_span] ,
  2161.  * l_span := [line_no, col1, col2].
  2162.  
  2163. macro TO_XREF(name) ;
  2164. if spans /= om and spans(current_node) /= om then
  2165.     XREF(name) := ( XREF(name) ? {} ) +
  2166.               { spans(current_node)(1)(1) } ;
  2167. end if
  2168. endm;
  2169. */
  2170. #define TO_XREF(name)
  2171.  
  2172. #define TO_ERRFILE(text) to_errfile(text)
  2173.  
  2174. /* streq() in misc.c tests strings for equality */
  2175.  
  2176. #define        errmsg_l(msg1,msg2,lrm,node)        \
  2177.             errmsg(strjoin(msg1,msg2),lrm,node)
  2178. #define        errmsg_l_id(msg1,msg2,name,lrm,node)    \
  2179.             errmsg_id(strjoin(msg1,msg2),name,lrm,node)
  2180. #define        errmsg_l_str(msg1,msg2,str,lrm,node)        \
  2181.             errmsg_str(strjoin(msg1,msg2),str,lrm,node)
  2182. extern int N_DEFINED[];
  2183.  
  2184. /* power_of_2. In SETL this procedure returns a tuple. In C it sets
  2185.  * global variables whose names begin with power_of_2_. Also needed
  2186.  * are two constants corresponding to the SETL strings 'exact'and
  2187.  * 'approximate'.
  2188.  */
  2189. #define POWER_OF_2_EXACT 0
  2190. #define POWER_OF_2_APPROXIMATE 1
  2191.  
  2192. #ifdef GEN
  2193. #include "ghdr.h"
  2194. #endif
  2195.  
  2196. #define TAG_RECORD              0
  2197. #define TAG_TASK                1
  2198. #define TAG_ACCESS              2
  2199. #define TAG_ARRAY               3
  2200. #define TAG_ENUM                4
  2201. #define TAG_FIXED               5
  2202. #define TAG_INT                 6
  2203. #define TAG_FLOAT               7
  2204.  
  2205. #endif
  2206.